<?php
Globals::requireController('Admin');
Globals::requireTable('Group');
Globals::requireTable('AclResource');

class AclController extends AdminController
{
	protected $groupTable;
	protected $aclResourceTable;
	
	public function __construct($config = null)
	{
		parent::__construct($config, 'acl');
		
		$this->groupTable		= new GroupTable($config);
		$this->aclResourceTable	= new AclResourceTable($config);
	}
	
	public function indexAction()
	{
		$this->view->groupData		= $this->groupTable->listAll(null, 'id ASC');
		$this->view->aclResourceData= $this->aclResourceTable->listAll(null, 'id ASC');
	}
	
	public function addAction()
	{
		$id = $this->acl->getTable()->add($this->getParams('groupid,resourceid'), true);
		$this->log('添加权限'.($id ? '成功(id: '.$id.')' : '失败'));
		$this->redirectToAction();
	}
	
	public function deleteAction()
	{
		$id = $this->getIntParam('id');
		$result = $this->acl->getTable()->delete($id);
		$this->log('删除权限'.($result ? '成功' : '失败').'(id: '.$id.')');
		$this->redirectToAction();
	}
}
